﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLThuChi.Models;

namespace QLThuChi.Reports
{
    public partial class FrmPrintPhieuChiLuong : Form
    {
        private List<PhieuChi_LuongNV> _lstPhieuChi;
        private string _congtrinh;

        public FrmPrintPhieuChiLuong(List<PhieuChi_LuongNV> lstItem, string congtrinh)
        {
            InitializeComponent();
            _lstPhieuChi = lstItem;
            _congtrinh = congtrinh;
        }

        private void FrmPrintPhieuChiLuong_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        public void LoadData()
        {
            var dt = new DataTable();
            dt.Columns.Add("STT");
            dt.Columns.Add("GiaiDoan");
            dt.Columns.Add("NhanCong");
            dt.Columns.Add("SoNgayCong");
            dt.Columns.Add("Luong");
            dt.Columns.Add("LuongNhanDuoc");
            dt.Columns.Add("NguoiLapPhieu");
            dt.Columns.Add("NgayLapPhieu");

            for (int i = 0; i < _lstPhieuChi.Count; i++)
            {
                dt.Rows.Add((i + 1).ToString(), _lstPhieuChi[i].GiaiDoan_NhanCong.CongTrinh_GiaiDoan.GiaiDoan.TenGiaiDoan, _lstPhieuChi[i].GiaiDoan_NhanCong.NhanCong.TenNhanCong, _lstPhieuChi[i].SoNgayCong.ToString(), String.Format("{0:#,##0;Nothing}", _lstPhieuChi[i].Luong), String.Format("{0:#,##0;Nothing}", _lstPhieuChi[i].Luong * _lstPhieuChi[i].SoNgayCong), _lstPhieuChi[i].NguoiDung.TenNguoiDung, String.Format("{0:dd/MM/yyyy}", _lstPhieuChi[i].NgayLapPhieu.Value));
            }

            rptThongKePhieuChiLuong rpt = new rptThongKePhieuChiLuong();
            rpt.DataDefinition.FormulaFields["TenCongTrinh"].Text = "'" + _congtrinh + "'";
            rpt.DataDefinition.FormulaFields["NgayThangNam"].Text = "'Ngày " + DateTime.Now.Day.ToString() + " tháng " + DateTime.Now.Month.ToString() + " năm " + DateTime.Now.Year.ToString() + "'";
            rpt.SetDataSource(dt);
            crystalReportViewer1.ReportSource = rpt;
        }
    }
}
